home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_force_protection.cog < prev    next >
Text File  |  1998-02-25  |  5KB  |  225 lines

  1. # Jedi Knight Cog Script
  2. #
  3. # FORCE_PROTECTION.COG
  4. #
  5. # FORCEPOWER Script - Protection
  6. #  Light Side Power
  7. #  Bin 29
  8. #
  9. # This script controls the activation and maintenance of force armor.
  10. # It uses Bin 61 for the armor amount.
  11. #
  12. # [YB]
  13. #
  14. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  15.  
  16.  
  17. symbols
  18.  
  19. thing       player                           local
  20.  
  21. flex        cost=300.0                       local
  22. flex        mana                             local
  23. flex        damage                           local
  24. flex        type                             local
  25. flex        forceArmor=0.0                   local
  26. flex        deterioration=5.0                local
  27.  
  28. int         count                            local
  29. int         limit                            local
  30. int         damageflags=30                   local
  31. int         rank                             local
  32.  
  33. int         shield=-1                        local
  34. template    shield_tpl=+force_shield         local
  35.  
  36. sound       protectionSound=ForceProtect01.wav  local
  37. sound       protectionSound2=ForceProtect02.wav local
  38. int         channel=-1                       local
  39.  
  40. vector      position                         local
  41.  
  42. int         inbubble=0                       local
  43.  
  44. message     startup
  45. message     damaged
  46. message     activated
  47. message     pulse
  48. message     newplayer
  49. message     killed
  50. message     selected
  51. message     enterbubble
  52. message     exitbubble
  53.  
  54. end
  55.  
  56. # ========================================================================================
  57.  
  58. code
  59.  
  60. startup:
  61.    player = GetLocalPlayerThing();
  62.    inbubble = 0;
  63.    call stop_power;
  64.  
  65.    Return;
  66.  
  67. # ........................................................................................
  68.  
  69. damaged:
  70.    damage = GetParam(0);
  71.    forceArmor = GetInv(player, 61);
  72.  
  73.    if(forceArmor > 0)
  74.    {
  75.       // If damage from energy, fire, magic, saber
  76.       type = GetParam(1);
  77.       if(type & damageflags)
  78.       {
  79.          // halve the damage from energy weapons
  80.          if(type == 2) damage = damage / 2;
  81.  
  82.          AddDynamicTint(player, 0, damage/100, damage/100);
  83.          forceArmor = forceArmor - damage;
  84.  
  85.          if(forceArmor < 0)
  86.             damage = -forceArmor;
  87.          else
  88.             damage = 0;
  89.  
  90.          // Inventory system will limit Bin 61 to a minimum of 0.
  91.          SetInv(player, 61, forceArmor);
  92.       }
  93.    }
  94.  
  95.    ReturnEx(damage);
  96.    Return;
  97.  
  98. # ........................................................................................
  99.  
  100. activated:
  101.  
  102.    if(inbubble) Return;
  103.  
  104.    mana = GetInv(player, 14);
  105.    if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  106.    {
  107.       if(!IsInvActivated(player, 29))
  108.       {
  109.          SetInvActivated(player, 29, 1);
  110.          if(GetInv(player, 64) != 1) ChangeInv(player, 14, -cost);
  111.  
  112.          // Send a "force disturbance"...
  113.          if(!IsMulti())
  114.             SendMessageExRadius(GetThingPos(player), cost, 0x4, splash, 29, 0, 0, 0);
  115.  
  116.          rank = GetInv(player, 29);
  117.  
  118.          PlayMode(player, 24);
  119.  
  120.          // Play activation sound
  121.          PlaySoundThing(protectionSound, player, 1.0, -1, -1, 0x80);
  122.  
  123.          // Play loop sound at 0.0 volume and fade it in to 0.8 volume in 0.75 secs
  124.          channel = PlaySoundThing(protectionSound2, player, 0.0, -1, -1, 0x81);
  125.          ChangeSoundVol(channel, 0.8, 0.75);
  126.  
  127.          // 75 hp of protection per rank
  128.          SetInv(player, 61, rank * 75);
  129.  
  130.          limit = rank * 5;
  131.  
  132.          // Create the shield
  133.          shield = CreateThingAtPos(shield_tpl, GetThingSector(player), GetThingPos(player) , '0 0 0');
  134.          AttachThingToThingEx(shield, player, 0x8);
  135.  
  136.          // Make the player magsealed
  137.          // SetThingFlags(player, 4);
  138.  
  139.          count = 0;
  140.          SetPulse(0.5);
  141.       }
  142.    }
  143.  
  144.    Return;
  145.  
  146. # ........................................................................................
  147.  
  148. pulse:
  149.    if(GetThingHealth(player) < 1)
  150.    {
  151.       call stop_power;
  152.       Return;
  153.    }
  154.  
  155.    forceArmor = GetInv(player, 61);
  156.  
  157.    count = count + 1;
  158.    if(count > limit)
  159.    {
  160.       forceArmor = forceArmor - deterioration;
  161.       SetInv(player, 61, forceArmor);
  162.    }
  163.  
  164.    if(forceArmor <= 0)
  165.    {
  166.       call stop_power;
  167.       Return;
  168.    }
  169.  
  170.    Return;
  171.  
  172. # ........................................................................................
  173.  
  174. selected:
  175.    jkPrintUNIString(player, 29);
  176.    Return;
  177.  
  178. # ........................................................................................
  179.  
  180. killed:
  181.    if(GetSenderRef() != player) Return;
  182.  
  183. newplayer:
  184.    call stop_power;
  185.    Return;
  186.  
  187. # ........................................................................................
  188.  
  189. enterbubble:
  190.    inbubble = 1;
  191.    call stop_power;
  192.    Return;
  193.  
  194. # ........................................................................................
  195.  
  196. exitbubble:
  197.    inbubble = 0;
  198.    Return;
  199.  
  200. # ........................................................................................
  201.  
  202. stop_power:
  203.    SetPulse(0);
  204.    if(channel != -1)
  205.    {
  206.       StopSound(channel, 0.1);
  207.       channel = -1;
  208.    }
  209.  
  210.    SetInvActivated(player, 29, 0);
  211.    // ClearThingFlags(player, 4);
  212.  
  213.    SetInv(player, 61, 0);
  214.    if(shield != -1)
  215.    {
  216.       DestroyThing(shield);
  217.       shield = -1;
  218.    }
  219.  
  220.    Return;
  221.  
  222. end
  223.  
  224.  
  225.